package com.bnz.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bnz.pojo.PageResult;
import com.bnz.pojo.R;
import com.bnz.pojo.Student;
import com.bnz.service.StudentService;
import com.sun.org.glassfish.gmbal.ParameterNames;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Reference
    private StudentService studentService;

    @RequestMapping("/list")
    public R findAll(){
      List<Student> students = studentService.findAll();
      return R.ok().data("list",students);
    }
    //分页cha
    @GetMapping("/findByPage/{page}/{pageSize}")
    public R findByPage(@PathVariable Integer page, @PathVariable Integer pageSize){
        PageResult<Student> pr = studentService.findPyPage(page,pageSize);
        return R.ok().data("pr",pr);
    }
    //条件加分页
    @PostMapping("/search")
    public R search(@PathVariable Integer page, @PathVariable Integer pageSize, @RequestBody Student student){

       PageResult<Student> pr = studentService.search(page,pageSize,student);
        return R.ok().data("pr",pr);
    }
    //增加
    @PostMapping("/add")
    public R save(@RequestBody Student student){
        studentService.add(student);
        return R.ok();
    }
    //修改
    @PostMapping("/update")
    public R update(@RequestBody Student student){
        studentService.update(student);
        return R.ok();
    }
    //删除
    @PostMapping("/delete/{ids}")
    public R delete(@PathVariable String[] ids){
        studentService.delete(ids);
        return R.ok().message("删除成功"); //返回问题 message
    }
}
